package main

import "fmt"

func main() {
	/*
		练习4：验证用户名密码是否正确
		var userList = map[string]map[string]string{
			"root":{"password":"123456", "tel":"158xxxxxxxx"},
			"admin":{"password":"123456", "tel":"158xxxxxxxx"},
			"xiaoming":{"password":"123456", "tel":"158xxxxxxxx"}}
		输入用户名密码，进行验证，验证成功后，输出手机号码

	*/
	var userList = map[string]map[string]string{
		"root":     {"password": "123456", "tel": "158xxxxxxxx"},
		"admin":    {"password": "123456", "tel": "158xxxxxxxx"},
		"xiaoming": {"password": "123456", "tel": "158xxxxxxxx"}}

	var user string
	var passwd string
	fmt.Printf("请输入用户名:")
	fmt.Scan(&user)
	for username, userinfo := range userList {
		if user == username {
			fmt.Printf("请输入密码: ")
			fmt.Scan(&passwd)
			for _, value := range userinfo {
				if passwd == value {
					fmt.Printf("恭喜您验证成功，手机号码为:%s", userinfo["tel"])
					return
				}
			}
		}
	}
	fmt.Println("用户名或密码错误")
}
